//
//  HWAssetsIncomeCell.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/27.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWAssetsIncomeCell: UITableViewCell {
    
    var bgView:UIView!
    var topLine:UIView!
    var bottomLine:UIView!
    var leftLine:UIView!
    var rightLine:UIView!
    var vLineOne:UIView!
    var vLineSecond:UIView!
    var vLineThree:UIView!
    var nameLabel:UILabel!
    var priceLabel:UILabel!
    var timeLabel:UILabel!
    var divideLabel:UILabel!
    
    var indexPath:IndexPath? {
        didSet {
            if indexPath?.row == 0 {
                topLine.isHidden = false
                bgView.backgroundColor = .colorWithHexString(hexString: "#FAFAFA")
                nameLabel.font = .boldSystemFont(ofSize: 14*widthScale)
                priceLabel.font = .boldSystemFont(ofSize: 14*widthScale)
                timeLabel.font = .boldSystemFont(ofSize: 14*widthScale)
                divideLabel.font = .boldSystemFont(ofSize: 14*widthScale)
            }else{
                topLine.isHidden = true
                bgView.backgroundColor = .white
                nameLabel.font = .systemFont(ofSize: 14*widthScale)
                priceLabel.font = .systemFont(ofSize: 14*widthScale)
                timeLabel.font = .systemFont(ofSize: 14*widthScale)
                divideLabel.font = .systemFont(ofSize: 14*widthScale)
            }
        }
    }
    var model:HWAssetsIncomeDetailModel? {
        didSet {
            nameLabel.text = model?.username
            priceLabel.text = model?.money
            timeLabel.text = model?.time
            divideLabel.text = model?.fencheng
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWAssetsIncomeCell) {
        let reUse:String = "HWAssetsIncomeCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWAssetsIncomeCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWAssetsIncomeCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgView = UIView()
        bgView.backgroundColor = .white
        contentView.addSubview(bgView)
        
        topLine = UIView()
        topLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(topLine)
        
        leftLine = UIView()
        leftLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(leftLine)
        
        bottomLine = UIView()
        bottomLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(bottomLine)
        
        rightLine = UIView()
        rightLine.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(rightLine)
        
        vLineOne = UIView()
        vLineOne.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(vLineOne)
        
        vLineSecond = UIView()
        vLineSecond.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(vLineSecond)
        
        vLineThree = UIView()
        vLineThree.backgroundColor = .colorWithHexString(hexString: "#EEEEEE")
        bgView.addSubview(vLineThree)
        
        nameLabel = HWLabel.createLabel(title: "用户SW7059833452", color: "#000000", font: 14*widthScale)
        nameLabel.numberOfLines = 2
        bgView.addSubview(nameLabel)
        
        priceLabel = HWLabel.createLabel(title: "充值 6 元", color: "#000000", font: 14*widthScale)
        priceLabel.numberOfLines = 2
        bgView.addSubview(priceLabel)
        
        timeLabel = HWLabel.createLabel(title: "11:58", color: "#000000", font: 14*widthScale)
        timeLabel.numberOfLines = 2
        timeLabel.textAlignment = .center
        bgView.addSubview(timeLabel)
        
        divideLabel = HWLabel.createLabel(title: "-", color: "#000000", font: 14*widthScale)
        divideLabel.numberOfLines = 2
        bgView.addSubview(divideLabel)
        
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.right.equalTo(-20*widthScale)
            make.top.bottom.equalToSuperview()
            make.height.equalTo(61*widthScale)
        }
        
        topLine.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(1*widthScale)
        }
        
        leftLine.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview()
            make.width.equalTo(1*widthScale)
        }
        
        bottomLine.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1*widthScale)
        }
        
        rightLine.snp.makeConstraints { make in
            make.right.top.bottom.equalToSuperview()
            make.width.equalTo(1*widthScale)
        }
        
        vLineOne.snp.makeConstraints { make in
            make.width.equalTo(1*widthScale)
            make.top.bottom.equalToSuperview()
            make.left.equalTo(110*widthScale)
        }
        
        vLineSecond.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.width.equalTo(1*widthScale)
//            make.right.equalTo(-90*widthScale)
            make.left.equalTo(vLineOne.snp.right).offset(70*widthScale)
//            56
        }
        
        vLineThree.snp.makeConstraints { make in
            make.width.equalTo(1*widthScale)
            make.top.bottom.equalToSuperview()
            make.right.equalTo(-70*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(8*widthScale)
            make.right.equalTo(vLineOne.snp.left).offset(-8*widthScale)
            make.centerY.equalToSuperview()
        }
        
        priceLabel.snp.makeConstraints { make in
            make.left.equalTo(vLineOne.snp.right).offset(8*widthScale)
            make.right.equalTo(vLineSecond.snp.left).offset(-8*widthScale)
            make.centerY.equalToSuperview()
        }
        
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(vLineSecond.snp.right).offset(8*widthScale)
            make.right.equalTo(vLineThree.snp.left).offset(0)
            make.centerY.equalToSuperview()
        }
        
        divideLabel.snp.makeConstraints { make in
            make.left.equalTo(vLineThree.snp.right).offset(8*widthScale)
            make.right.equalTo(rightLine.snp.left).offset(-8*widthScale)
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
